/*
* (C) Copyright 2013 Philip Kirchhoff 
* 
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*-------------------------------------------------------------------------------
* This file is part of the DataLogger library by Philip Kirchhoff
* https://code.google.com/p/pk-data-logger/
* SVN: http://pk-data-logger.googlecode.com/svn/trunk
*-------------------------------------------------------------------------------
* Module    : DlDataset.h   
* Author    : Kirchhoff, Philip
* Date      : 01.04.2013
*-------------------------------------------------------------------------------
* Header file for DlDataset class
*   
*-------------------------------------------------------------------------------
* Change History:
* 01.04.2013  Kirchhoff 	Created
--------------------------------------------------------------------------------
*/

#ifndef DL_DATASET_H
#define DL_DATASET_H

#include <string>
#include <vector>

#include "DlTimestamp.h"
#include "DlDataChannel.h"
#include "DlLongChannel.h"
#include "DlULongChannel.h"
#include "DlShortChannel.h"
#include "DlUShortChannel.h"
#include "DlDoubleChannel.h"
#include "DlFloatChannel.h"
#include "DlStringChannel.h"
#include "DlBoolChannel.h"


/******************************************************************************//**
 * @brief Represents a DataLogger dataset
 *********************************************************************************/
class DlDataset
{
public:
    /**************************************************************************//**
    * @brief Constructs an empty DataLogger dataset
    ******************************************************************************/
    DlDataset();

    /**************************************************************************//**
    * @brief Destructor
    ******************************************************************************/
    ~DlDataset();

    /**************************************************************************//**
    * @brief Creates an empty channel an adds it to the dataset
    ******************************************************************************/
    DlDataChannel* newDataChannel(DlDataChannel::ChannelType chanType,
                                  std::string chanId,
                                  std::string chanUnit = std::string("-"),
                                  std::string chanDescr = std::string("-"));

    /**************************************************************************//**
    * @brief Sets the datasets start timestamp
    * @param timeStamp Timestamp object
    ******************************************************************************/
    void setStartTime(DlTimestamp timeStamp){mStartTimeStamp = timeStamp;}

    /**************************************************************************//**
    * @brief Sets the datasets trigger timestamp
    * @param timeStamp Timestamp object
    ******************************************************************************/
    void setTriggerTime(DlTimestamp timeStamp){mTriggerTimeStamp = timeStamp;}

    /**************************************************************************//**
    * @brief Sets the sample rate
    ******************************************************************************/
    void setSampleRate(double sampleRate){mSampleRate = sampleRate;}

    /**************************************************************************//**
    * @brief Get a selected sample rate
    ******************************************************************************/
    double sampleRate();

    /**************************************************************************//**
    * @brief Get a channel from the dataset
    ******************************************************************************/
    DlDataChannel* channel(unsigned int chanNum);

    /**************************************************************************//**
    * @brief Adds complete a set of samples to the dataset
    ******************************************************************************/
    void addSamples(void **ppSamples);

    /**************************************************************************//**
    * @brief Get the timestamp offset for a selected sample relative to the start
    *			sample
    ******************************************************************************/
    double offsetForSample(unsigned int sampleNum);

    /**************************************************************************//**
    * @brief Get the datasets start timestamp
    * @return Start timestamp object
    ******************************************************************************/
    DlTimestamp startTime(){return mStartTimeStamp;}

    /**************************************************************************//**
    * @brief Get the datasets trigger timestamp
    * @return Trigger timestamp object
    ******************************************************************************/
    DlTimestamp triggerTime(){return mTriggerTimeStamp;}

    /**************************************************************************//**
    * @brief Get the total number of channels(analog+status) in the dataset
    * @return Total number of channels
    ******************************************************************************/
    unsigned int numChannnels(){return mChannels.size();}

    /**************************************************************************//**
    * @brief Clear dataset. This removes all data channel
    ******************************************************************************/
    void clear();


private:
    DlTimestamp mStartTimeStamp;
    DlTimestamp mTriggerTimeStamp;
    double mSampleRate;

    std::vector<DlDataChannel*> mChannels;

};

#endif
